
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 *
 */

package com.hlkj.pay.app.token.ext.impl;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.extension.annotation.Extension;
import com.hlkj.pay.app.token.ext.AuthTokenExtPt;
import com.hlkj.pay.common.TenantSecretContext;
import com.hlkj.pay.common.constants.TenantAuthConstant;
import com.hlkj.pay.enums.AuthTokenEnum;
import com.hlkj.pay.infrastructure.model.token.TokenSecretDO;
import com.hlkj.pay.service.token.impl.TokenCommonService;
import com.hlkj.pay.vo.common.req.token.AuthTokenClientRequest;
import com.hlkj.pay.vo.common.req.token.PhoneTokenRequest;
import com.hlkj.pay.vo.common.resp.token.OauthTokenResp;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author HlpayTeam
 * @date 2024/09/30 10:42
 */
@Slf4j
@Service
@Extension(bizId = TenantAuthConstant.CLIENT)
@AllArgsConstructor
public class ClientTokenServiceExt implements AuthTokenExtPt {

    private final TokenCommonService tokenCommonService;

    /**
     * OauthTokenResp
     * 
     * @return
     */
    @Override
    public CommonResult<OauthTokenResp> oauthToken(AuthTokenClientRequest authTokenClientRequest) {
        PhoneTokenRequest phoneTokenRequest = (PhoneTokenRequest) authTokenClientRequest;
        TokenSecretDO tenantSecretDO = TenantSecretContext.get();
        OauthTokenResp oauthTokenResp = tokenCommonService.clientToken(tenantSecretDO);
        tokenCommonService.addTenantAuthLog(tenantSecretDO, oauthTokenResp, AuthTokenEnum.AUTH_TOKEN_REQUEST_TYPE.CLIENT);
        return CommonResult.success(oauthTokenResp);
    }

}
